package com.huaguoguo.cyg.vcs;

import com.huaguoguo.cyg.entity.po.SVNCommintLog;
import com.huaguoguo.cyg.utils.MyUtils;
import com.huaguoguo.cyg.vcs.manager.VersionControlManager;
import com.huaguoguo.cyg.vcs.manager.impl.GitManager;
import com.huaguoguo.cyg.vcs.manager.impl.SVNManager;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.util.List;

/**
 * 类说明： svn服务调用类<br/>
 * author:huaguoguo
 * Date: 2020/3/24
 * Time: 18:39
 */
@Slf4j
public class VersionControlApi {

    /**
     * 导出svn最近10次的提交记录
     * @param moduleRootPath 模块根目录
     * @param expPath 导出路径
     * @param commiterName 提交人
     */
    public static void expSVNLastTenCommit(String moduleRootPath,String expPath,String commiterName) throws IOException {
        SVNManager svnManager = new SVNManager();
        svnManager.init(moduleRootPath, expPath, commiterName);
        svnManager.execLogCmd();
        MyUtils.openDirWindow(expPath);
        List<List<String>> lists = svnManager.parseSVNLogFile();
        List<SVNCommintLog> svnCommintLogList = svnManager.getSVNCommintLogList(lists);
        svnManager.copyAndMoveCommitFile(svnCommintLogList);
    }

    /**
     * 导出 git 最近10次的提交记录
     * @param moduleRootPath 模块根目录
     * @param expPath 导出路径
     * @param commiterName 提交人
     */
    public static void expGitLastTenCommit(String moduleRootPath,String expPath,String commiterName) throws IOException {
        GitManager gitManager = new GitManager();
        gitManager.init(moduleRootPath, expPath, commiterName);
        gitManager.execLogCmd();
        MyUtils.openDirWindow(expPath);
        List<List<String>> lists = gitManager.parseSVNLogFile();
        List<SVNCommintLog> svnCommintLogList = gitManager.getSVNCommintLogList(lists);
        gitManager.copyAndMoveCommitFile(svnCommintLogList);
    }
}
